package design.strategy;

/**
 * 简单策略模式
 */
abstract class Strategy {
    public abstract void algInterface();
}

class ConcreteStrategyA extends Strategy {
    @Override
    public void algInterface() {
        System.out.println("stratege A");
    }
}

class ConcreteStrategyB extends Strategy {
    @Override
    public void algInterface() {
        System.out.println("stratege B");
    }
}

class Context {
    private Strategy strategy;
    // set strategy
    public Context(Strategy strategy) {
        this.strategy = strategy;
    }
    // execute strategy
    public void contextInterface() {
        strategy.algInterface();
    }
}

public class ProcessStrategy {
    public static void main(String[] args) {
        Context contextA = new Context(new ConcreteStrategyA());
        Context contextB = new Context(new ConcreteStrategyB());
        contextA.contextInterface();
        contextB.contextInterface();
    }
}